package com.example.controller;


import com.example.common.utils.ResponseResult;
import com.example.service.IAccountService;
import com.example.vo.req.LoginReqVO;
import com.example.vo.req.RegisterReqVO;
import com.example.vo.resp.AuthorizeRespVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hbin
 * @since 2025-01-04
 */
@RestController
@RequestMapping("/account")
public class AccountController {
    
    @Resource
    private IAccountService accountService;

    /**
     * 注册接口
     * @param requestParam 注册请求参数
     */
    @PostMapping("/register")
    public ResponseResult register(@Validated @RequestBody RegisterReqVO requestParam) {
        accountService.doRegister(requestParam);
        return ResponseResult.success();
    }

    /**
     * 登录接口
     * @param requestParam 登录请求参数
     * @return 授权信息
     */
    @PostMapping("/login")
    public ResponseResult login(@Validated @RequestBody LoginReqVO requestParam) {
        AuthorizeRespVO authorizeVO = accountService.doLogin(requestParam);
        return ResponseResult.success(authorizeVO);
    }

    /**
     * 获取账号信息
     * @return 结果
     */
    @GetMapping("/info")
    public ResponseResult info() {
        return ResponseResult.success("info data");
    }
    
}
